/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DefaultAnalysisResultPanel.java
 *
 * Created on 2010-04-18, 17:57:35
 */
package pl.tom.social.analyzer.gui.panel;

import java.awt.FileDialog;
import javax.swing.JFrame;
import javax.swing.JTable;
import pl.tom.social.common.persist.CsvDumper;

/**
 *
 * @author Tom
 */
public class DefaultAnalysisResultPanel extends javax.swing.JPanel {

	JTable table;

	/** Creates new form DefaultAnalysisResultPanel */
	public DefaultAnalysisResultPanel(JTable table) {
		initComponents();
		this.table = table;
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        saveToCSVButton = new javax.swing.JButton();

        saveToCSVButton.setText(org.openide.util.NbBundle.getMessage(DefaultAnalysisResultPanel.class, "DefaultAnalysisResultPanel.saveToCSVButton.text")); // NOI18N
        saveToCSVButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveToCSVButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(saveToCSVButton)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(saveToCSVButton)
        );
    }// </editor-fold>//GEN-END:initComponents

	private void saveToCSVButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveToCSVButtonActionPerformed
		JFrame frame = new JFrame();
		FileDialog dialog = new FileDialog(frame, "Save file", FileDialog.SAVE);
		dialog.setVisible(true);
		String fileName = dialog.getFile();
		if (fileName != null && fileName.length() > 0) {
			CsvDumper.dump(table, fileName);
		}
	}//GEN-LAST:event_saveToCSVButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton saveToCSVButton;
    // End of variables declaration//GEN-END:variables
}
